#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
    int n;
    cin>>n;
    vector<int>v(n+1);
    int mn=INT_MAX;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        mn=min(mn,v[i]);
    }
    int ans=mn*(n-1);
    for(int i=2;i<=n;i++)
    {
        if(v[i]==v[i-1])
        {
            int tmp=2,x=v[i];
            while(i+1<=n&&v[i+1]==x)
            {
                tmp++;
                i++;
            }
            ans=min(ans,(n-tmp)*x);
        }
    }
    cout<<ans<<endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T=1;
    cin>>T;
    while(T--)
    {
       solve();
    }
    return 0;
}